﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Services;
using MethodWorx.CMS.Content;
using MethodWorx.CMS.Plugins;

namespace MethodWorx.CMS.Requests
{
    public class UpdateContentTemplatePropertiesRequest : UpdatePropertiesRequest
    {
        private ContentTemplateService service;
        private ContentTemplate contentTemplate;

        public UpdateContentTemplatePropertiesRequest(ContentTemplateService service, Guid id)
        {
            this.service = service;
            this.contentTemplate = service.GetContentTemplateById(id);
        }

        public override void Complete()
        {
            if (service == null)
                throw new ArgumentNullException("service");

            //  perform the request on the service
            this.service.UpdateContentTemplateProperties(this);
        }

        public override void Add(string name, bool mandatory, string type, ICustomPropertyDetails custom)
        {
            this.contentTemplate.Properties.Add(name, mandatory, type, custom);
        }

        public override void Clear()
        {
            this.contentTemplate.Properties.Clear();
        }

        internal ContentTemplate ContentTemplate
        {
            get { return this.contentTemplate; }
        }

    }
}
